<template>
    <card>
        <card-block>抓取ID：{{result.id}}</card-block>
        <!--<card-block>创建用户：{{result.user_id}}</card-block>-->
        <card-block><a target="_blank" :href="'https://tieba.baidu.com/p/'+result.post_id">查看原帖</a></card-block>
        <card-block>
            <template v-if="result.status===0">
                正在队列中
            </template>
            <template v-else-if="result.status===1">
                正在处理中
            </template>
            <template v-else-if="result.status===2">
                开始抓取：第{{result.current_page}}页，共{{result.total_page}}页
            </template>
            <template v-else-if="result.status===3">
                抓取完毕，正在存入数据库
            </template>
            <template v-else-if="result.status===4">
                抓取成功，<a :href="'/repositories/'+result.repository_id">点击查看</a>
            </template>
        </card-block>
    </card>
</template>

<script>
    export default {
        name: "TigTieba", data: function () {
            return {interval: null, result: {}}
        }, created: function () {
            const that = this;
            const query = function () {
                axios.get('/tieba/' + that.id + '/status').then(function (res) {
                    that.result = res.data;
                    if (res.data.status === 4) {
                        clearInterval(that.interval);
                    }
                });

            };
            query();
            this.interval = setInterval(query, 2000);
        }, props: {id: Number}
    }
</script>

<style scoped>

</style>